/*
package com.lianyu507.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;



*/
/**
 * Created by Snowy on 2017/11/22.
 *//*

public class ExcelUtil {
  */
/*  public static String NO_DEFINE="no_define";//未定义的字段
    public static String DEFALULT_DATE_PATTERN="yyyy年MM月dd日";//默认的日期格式
    public static int DEFAULT_COLOUMN_WIDTH=17;
    *//*
*/
/*导出excel的主要工具类方法*//*
*/
/*
    public static void exportExcel(String title, Map<String,String> headMap, JSONArray jsonArray
            , int colWidth,String dataPattern, OutputStream out){
        if(dataPattern==null) dataPattern = DEFALULT_DATE_PATTERN;
//        首先需要声明一个工作簿
        HSSFWorkbook workbook = new HSSFWorkbook();
        workbook.createInformationProperties();
        workbook.getDocumentSummaryInformation().setCompany("炼狱507");
        SummaryInformation si = workbook.getSummaryInformation();
        si.setAuthor("劉浩");
        si.setApplicationName("日志統計表");
        si.setCreateDateTime(new Date());
        si.setTitle("GetWordsLog");
        si.setLastAuthor("liuhao");
        si.setSubject("Poi導出到excel");
        si.setComments("POI开发者之一");
        //表头样式
        HSSFCellStyle titleStyle = workbook.createCellStyle();
        titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        HSSFFont titleFont = workbook.createFont();
        titleFont.setFontHeightInPoints((short) 20);
        titleFont.setBoldweight((short) 700);
        titleStyle.setFont(titleFont);
//        设置列头样式
        HSSFCellStyle headStyle = workbook.createCellStyle();
        *//*
*/
/*headStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);*//*
*/
/*
        headStyle.setBorderBottom(HSSFCellStyle.VERTICAL_CENTER);
        headStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        headStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        headStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        headStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        HSSFFont headFont = workbook.createFont();
        headFont.setFontHeightInPoints((short) 12);
        headFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        headStyle.setFont(headFont);

        // 单元格样式
        HSSFCellStyle cellStyle = workbook.createCellStyle();
        *//*
*/
/*cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);*//*
*/
/*
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        HSSFFont cellFont = workbook.createFont();
        cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
        cellStyle.setFont(cellFont);
        //生成一个带标题的表格
        HSSFSheet sheet = workbook.createSheet();
        //声明一个画图的顶级管理器
        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
        // 定义注释的大小和位置
        HSSFComment comment = patriarch.createComment(new HSSFClientAnchor(0,
                0, 0, 0, (short) 4, 2, (short) 6, 5));
        comment.setString(new HSSFRichTextString("可以在POI中添加注释"));
        // 设置注释作者，当鼠标移动到单元格上是可以在状态栏中看到该内容.
        comment.setAuthor("Jack");
//      设置列宽
        int minBytes = colWidth < DEFAULT_COLOUMN_WIDTH ? DEFAULT_COLOUMN_WIDTH:colWidth;//至少字节数
        int[] arrColWidth = new int[headMap.size()];
        // 产生表格标题行,以及设置列宽
        String[] properties = new String[headMap.size()];
        String[] headers = new String[headMap.size()];
        int ii=0;
        //通过foreach方法遍历map集合

        for (Iterator<String> iter = headMap.keySet().iterator();iter.hasNext();){
            String filedName = iter.next();
            properties[ii] = filedName;
            headers[ii]=filedName;

            int bytes = filedName.getBytes().length;
            arrColWidth[ii]=bytes < minBytes ? minBytes:bytes;
            sheet.setColumnWidth(ii,arrColWidth[ii]*256);
            ii++;
        }
//        遍历集合产生数据行
        int rowIndex=0;
        for (Object obj : jsonArray){
            if (rowIndex==65535 || rowIndex==0){
                if (rowIndex !=0 ){
//                    如果数据超过了，则在第二页显示
                    sheet = workbook.createSheet();
                }
                HSSFRow titleRow = sheet.createRow(0);//表頭 rowIndex=0
                titleRow.createCell(0).setCellValue(title);
                titleRow.getCell(0).setCellStyle(titleStyle);
                sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headMap.size() - 1));

                HSSFRow headerRow = sheet.createRow(1);
                for (int i=0;i<headers.length;i++){
                    headerRow.createCell(i).setCellValue(headers[i]);
                    headerRow.getCell(i).setCellStyle(headStyle);
                }
                rowIndex = 2;//数据内容从 rowIndex=2开始

            }
//            將obj对象转化为JSONObject
            JSONObject jo = (JSONObject) JSONObject.toJSON(obj);
            HSSFRow dataRow = sheet.createRow(rowIndex);
            for (int i = 0; i < properties.length; i++) {
                HSSFCell newCell = dataRow.createCell(i);

                Object o = jo.get(properties[i]);
                String cellValue="";
                if(o==null) cellValue = "";
                else if(o instanceof Date) cellValue = new SimpleDateFormat(dataPattern).format(o);
                else cellValue = o.toString();

                newCell.setCellValue(cellValue);
                newCell.setCellStyle(cellStyle);


            }

            rowIndex++;

        }
        // 自动调整宽度
        *//*
*/
/*for (int i = 0; i < headers.length; i++) {
            sheet.autoSizeColumn(i);
        }*//*
*/
/*
        try {
            workbook.write(out);
            workbook.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static void exportExcelX(String title,Map<String, String> headMap,JSONArray jsonArray,String datePattern,int colWidth, OutputStream out) {
        if(datePattern==null) datePattern = DEFALULT_DATE_PATTERN;
        // 声明一个工作薄
        SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
        workbook.setCompressTempFiles(true);
        //表头样式
        CellStyle titleStyle = workbook.createCellStyle();
        titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        Font titleFont = workbook.createFont();
        titleFont.setFontHeightInPoints((short) 20);
        titleFont.setBoldweight((short) 700);
        titleStyle.setFont(titleFont);
        // 列头样式
        CellStyle headerStyle = workbook.createCellStyle();
        *//*
*/
/*headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);*//*
*/
/*
        headerStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        headerStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        headerStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        headerStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        Font headerFont = workbook.createFont();
        headerFont.setFontHeightInPoints((short) 12);
        headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        headerStyle.setFont(headerFont);
        // 单元格样式
        CellStyle cellStyle = workbook.createCellStyle();
     *//*
*/
/*   cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);*//*
*/
/*
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        Font cellFont = workbook.createFont();
        cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
        cellStyle.setFont(cellFont);
        // 生成一个(带标题)表格
        SXSSFSheet sheet = workbook.createSheet();
        //设置列宽
        int minBytes = colWidth<DEFAULT_COLOUMN_WIDTH?DEFAULT_COLOUMN_WIDTH:colWidth;//至少字节数
        int[] arrColWidth = new int[headMap.size()];
        // 产生表格标题行,以及设置列宽
        String[] properties = new String[headMap.size()];
        String[] headers = new String[headMap.size()];
        int ii = 0;
        for (Iterator<String> iter = headMap.keySet().iterator(); iter
                .hasNext();) {
            String fieldName = iter.next();

            properties[ii] = fieldName;
            headers[ii] = headMap.get(fieldName);

            int bytes = fieldName.getBytes().length;
            arrColWidth[ii] =  bytes < minBytes ? minBytes : bytes;
            sheet.setColumnWidth(ii,arrColWidth[ii]*256);
            ii++;
        }
        // 遍历集合数据，产生数据行
        int rowIndex = 0;
        for (Object obj : jsonArray) {
            if(rowIndex == 65535 || rowIndex == 0){
                if ( rowIndex != 0 ) sheet = workbook.createSheet();//如果数据超过了，则在第二页显示

                SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
                titleRow.createCell(0).setCellValue(title);
                titleRow.getCell(0).setCellStyle(titleStyle);
                sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headMap.size() - 1));

                SXSSFRow headerRow = sheet.createRow(1); //列头 rowIndex =1
                for(int i=0;i<headers.length;i++)
                {
                    headerRow.createCell(i).setCellValue(headers[i]);
                    headerRow.getCell(i).setCellStyle(headerStyle);

                }
                rowIndex = 2;//数据内容从 rowIndex=2开始
            }
            JSONObject jo = (JSONObject) JSONObject.toJSON(obj);
            SXSSFRow dataRow = sheet.createRow(rowIndex);
            for (int i = 0; i < properties.length; i++)
            {
                SXSSFCell newCell = dataRow.createCell(i);

                Object o =  jo.get(properties[i]);
                String cellValue = "";
                if(o==null) cellValue = "";
                else if(o instanceof Date) cellValue = new SimpleDateFormat(datePattern).format(o);
                else if(o instanceof Float || o instanceof Double)
                    cellValue= new BigDecimal(o.toString()).setScale(2,BigDecimal.ROUND_HALF_UP).toString();
                else cellValue = o.toString();

                newCell.setCellValue(cellValue);
                newCell.setCellStyle(cellStyle);
            }
            rowIndex++;
        }
        // 自动调整宽度
        *//*
*/
/*for (int i = 0; i < headers.length; i++) {
            sheet.autoSizeColumn(i);
        }*//*
*/
/*
        try {
            workbook.write(out);
            workbook.close();
            workbook.dispose();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }*//*

   */
/* public static void exportExcelX(String title, Map<String,String> headMap, JSONArray jsonArray
            , int colWidth,String dataPattern, OutputStream out){
        if (dataPattern==null){
            dataPattern = DEFALULT_DATE_PATTERN;
        }
//        声明一个工作簿
        *//*
*/
/*new SXSSFWorkbook();*//*
*/
/*
        SXSSFWorkbook workbook = new SXSSFWorkbook(1000);
        workbook.setCompressTempFiles(true);
//        创建表头
        CellStyle titleStyle = workbook.createCellStyle();
        titleStyle.setBorderBottom(HSSFCellStyle.ALIGN_CENTER);
        Font titleFont = workbook.createFont();
        titleFont.setFontHeightInPoints((short) 20);
        titleFont.setBoldweight((short) 700);
        titleStyle.setFont(titleFont);
//        创建列头样式
        CellStyle headerStyle = workbook.createCellStyle();
        headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        headerStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        headerStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        headerStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        headerStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        Font headFont = workbook.createFont();
        headFont.setFontHeightInPoints((short) 12);
        headFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        headerStyle.setFont(headFont);
//      设置单元格样式
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        Font cellFont = workbook.createFont();
        cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
        cellStyle.setFont(cellFont);
//        生成一个（带标题）表格
        SXSSFSheet sheet = workbook.createSheet();
//        设置列宽
        int minBytes = colWidth < DEFAULT_COLOUMN_WIDTH ? DEFAULT_COLOUMN_WIDTH:colWidth; //至少字节数
        int[] arrColWidth =  new int[headMap.size()];
        // 产生表格标题行,以及设置列宽
        String[] properties = new String[headMap.size()];
        String[] headrs = new String[headMap.size()];
        int ii=0;
        for (Iterator<String> iter =headMap.keySet().iterator();iter.hasNext();){
            String fieldName = iter.next();

            properties[ii] = fieldName;
            headrs[ii] = headMap.get(fieldName);

            int bytes = fieldName.getBytes().length;
            arrColWidth[ii] =  bytes < minBytes ? minBytes : bytes;
            sheet.setColumnWidth(ii,arrColWidth[ii]*256);
            ii++;
        }

//        遍历集合数据，产生数据行。
        int rowIndex = 0;
        for (Object obj : jsonArray) {
            if(rowIndex == 65535 || rowIndex == 0){
                if ( rowIndex != 0 ) sheet = workbook.createSheet();//如果数据超过了，则在第二页显示

                SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
                titleRow.createCell(0).setCellValue(title);
                titleRow.getCell(0).setCellStyle(titleStyle);
                sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headMap.size() - 1));

                SXSSFRow headerRow = sheet.createRow(1); //列头 rowIndex =1
                for(int i=0;i<headrs.length;i++)
                {
                    headerRow.createCell(i).setCellValue(headrs[i]);
                    headerRow.getCell(i).setCellStyle(headerStyle);

                }
                rowIndex = 2;//数据内容从 rowIndex=2开始
            }
            JSONObject jo = (JSONObject) JSONObject.toJSON(obj);
            SXSSFRow dataRow = sheet.createRow(rowIndex);
            for (int i = 0; i < properties.length; i++)
            {
                SXSSFCell newCell = dataRow.createCell(i);

                Object o =  jo.get(properties[i]);
                String cellValue = "";
                if(o==null) cellValue = "";
                else if(o instanceof Date) cellValue = new SimpleDateFormat(dataPattern).format(o);
                else if(o instanceof Float || o instanceof Double)
                    cellValue= new BigDecimal(o.toString()).setScale(2,BigDecimal.ROUND_HALF_UP).toString();
                else cellValue = o.toString();

                newCell.setCellValue(cellValue);
                newCell.setCellStyle(cellStyle);
            }
            rowIndex++;
        }
        // 自动调整宽度
        *//*
*/
/*for (int i = 0; i < headers.length; i++) {
            sheet.autoSizeColumn(i);
        }*//*
*/
/*
        try {
            workbook.write(out);
            workbook.close();
            workbook.dispose();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }*//*


}
*/
package com.lianyu507.util;

import com.lianyu507.model.ExcelBean;

import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.sql.Date;
import java.util.List;
import java.util.Map;
//Sheet cell  row  页 列 行
public class ExcelUtil {
    private final static String excel2003L=".xls";//2003版本
    private  final static String excel2007U=".xlsx";//2007版本
    //    Excel表格导出
    /*clazz 数据源model类型
    objs excel标题列及对应model字段名
    map 标题列行数以及cell字体样式
    * */
    public static XSSFWorkbook createExcelFile(Class clazz, List objs, Map<Integer,List<ExcelBean>> map,String sheetName) throws Exception{
//创建一个新的Excel工作簿
        XSSFWorkbook workbook = new XSSFWorkbook();
        //在Excel工作簿中建一个工作表，
        XSSFSheet sheet = workbook.createSheet(sheetName);
        //创建字体样式
        createFont(workbook);
        //创建标题
        createTableHeader( sheet,map );
        //创建内容
        createTableRows(sheet,map,objs,clazz);
        return  workbook;
    }
    private static XSSFCellStyle fontStyle;
    private static XSSFCellStyle fontStyle2;
    public static void createFont(XSSFWorkbook workbook){
        //表头
        fontStyle = workbook.createCellStyle();
        XSSFFont  font1 = workbook.createFont();
        font1.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
        font1.setFontName("黑体");
        font1.setFontHeightInPoints((short) 10);
        fontStyle.setFont(font1);
        fontStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);//下边框
        fontStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);//左边框
        fontStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);//上边框
        fontStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);//右边框
        fontStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);//居中
        //内容
        fontStyle2=workbook.createCellStyle();
        XSSFFont font2=workbook.createFont();
        font2.setFontName("宋体");
        font2.setFontHeightInPoints((short)16);
        fontStyle2.setFont(font2);
        fontStyle2.setBorderBottom(XSSFCellStyle.BORDER_THIN);//下边框
        fontStyle2.setBorderBottom(XSSFCellStyle.BORDER_THIN);//左边框
        fontStyle2.setBorderBottom(XSSFCellStyle.BORDER_THIN);//上边框
        fontStyle2.setBorderBottom(XSSFCellStyle.BORDER_THIN);//右边框
        fontStyle2.setAlignment(XSSFCellStyle.ALIGN_CENTER);//居中
    }
    /*
    * sheet 工作簿
    * map 每行每个单元格对应的列头信息
    * */
    public static final void createTableHeader(XSSFSheet sheet,Map<Integer,List<ExcelBean>> map){
        int startIndex = 0;//cell起始位置
        int endIndex=0;//cell终止位置
        for (Map.Entry<Integer,List<ExcelBean>> entry:map.entrySet()){
            XSSFRow row = sheet.createRow(entry.getKey());
            List<ExcelBean> excels=entry.getValue();
            for (int x=0;x<excels.size();x++){
                //合并单元格
                if (excels.get(x).getCols()>1){
                    if (x==0){
                        endIndex+=excels.get(x).getCols()-1;
                        CellRangeAddress range=new CellRangeAddress(0,0,startIndex,endIndex);
                        sheet.addMergedRegion(range);
                        startIndex+=excels.get(x).getCols();
                    }else {
                        endIndex+=excels.get(x).getCols();
                        CellRangeAddress range=new CellRangeAddress(0,0,startIndex,endIndex);
                        sheet.addMergedRegion(range);
                        startIndex+=excels.get(x).getCols();
                    }
                    XSSFCell cell = row.createCell(startIndex-excels.get(x).getCols());
                    cell.setCellValue(excels.get(x).getHeadTextName());//设置内容
                    if(excels.get(x).getCellStyle()!=null){
                        cell.setCellStyle(excels.get(x).getCellStyle());//设置格式
                    }
                    cell.setCellStyle(fontStyle);
                }else{
                    XSSFCell cell =row.createCell(x);
                    cell.setCellValue(excels.get(x).getHeadTextName());//设置内容
                    if (excels.get(x).getCellStyle()!=null){
                        cell.setCellStyle(excels.get(x).getCellStyle());
                    }
                    cell.setCellStyle(fontStyle);
                }
            }
        }
    }
    public static void createTableRows(XSSFSheet sheet,Map<Integer,List<ExcelBean>> map,List objs,Class clazz) throws Exception{
        int rowindex=map.size();
        int maxKey=0;
        List<ExcelBean> ems = new ArrayList<ExcelBean>();
        for (Map.Entry<Integer,List<ExcelBean>> entry:map.entrySet()){
            if (entry.getKey()>maxKey){
                maxKey=entry.getKey();
            }
        }
        ems=map.get(maxKey);
        List<Integer> widths= new ArrayList<Integer>(ems.size());
        for (Object obj:objs){
            XSSFRow  row =sheet.createRow(rowindex);
            for (int i=0;i<ems.size();i++){
                ExcelBean em=ems.get(i);
                PropertyDescriptor pd=new PropertyDescriptor(em.getPropertyName(),clazz);
                Method getMethod = pd.getReadMethod();
                Object rtn = getMethod.invoke(obj);
                String  value="";
                //如果是日期类型需要进行转换
                if (rtn!=null){
                    if (rtn instanceof Date){
                        value = DateUtil.dateToString( (java.sql.Date) rtn );
                    }else if(rtn instanceof BigDecimal){
                        NumberFormat nf=new DecimalFormat("#,##0.00");
                        value=nf.format( (BigDecimal)rtn).toString();
                    }else if ((rtn instanceof  Integer)&&(Integer.valueOf( rtn.toString())<0)){
                        value="-";
                    }else{
                        value=rtn.toString();
                    }
                }
                XSSFCell cell = row.createCell(i);
                cell.setCellValue(value);
                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                cell.setCellStyle(fontStyle2);
                //最大列宽
                int width=value.getBytes().length*300;
                //设置当前
                if (widths.size()<=i){
                    widths.add(width);
                    continue;
                }
                //比原来大，更新数据
                if (width>widths.get(i)){
                    widths.set(i,width);
                }
            }
            rowindex++;
        }
        //设置列宽
        for (int index=0;index<widths.size();index++){
            Integer width=widths.get(index);
            width=width<2500?2500:width+300;
            width=width>10000?10000+300:width+300;
            sheet.setColumnWidth(index,width);
        }
    }
}
